home *** CD-ROM | disk | FTP | other *** search
- package javax.activation;
-
- import java.awt.datatransfer.DataFlavor;
- import java.awt.datatransfer.Transferable;
- import java.awt.datatransfer.UnsupportedFlavorException;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.PipedInputStream;
- import java.io.PipedOutputStream;
- import java.net.URL;
-
- public class DataHandler implements Transferable {
- private DataSource dataSource = null;
- private DataSource objDataSource = null;
- private Object object = null;
- private String objectMimeType = null;
- private CommandMap currentCommandMap = null;
- private static final DataFlavor[] emptyFlavors = new DataFlavor[0];
- private DataFlavor[] transferFlavors;
- private DataContentHandler dataContentHandler;
- private DataContentHandler factoryDCH;
- private static DataContentHandlerFactory factory = null;
- private DataContentHandlerFactory oldFactory;
- private String shortType;
-
- public DataHandler(DataSource var1) {
- this.transferFlavors = emptyFlavors;
- this.dataContentHandler = null;
- this.factoryDCH = null;
- this.oldFactory = null;
- this.shortType = null;
- this.dataSource = var1;
- this.oldFactory = factory;
- }
-
- public DataHandler(Object var1, String var2) {
- this.transferFlavors = emptyFlavors;
- this.dataContentHandler = null;
- this.factoryDCH = null;
- this.oldFactory = null;
- this.shortType = null;
- this.object = var1;
- this.objectMimeType = var2;
- this.oldFactory = factory;
- }
-
- public DataHandler(URL var1) {
- this.transferFlavors = emptyFlavors;
- this.dataContentHandler = null;
- this.factoryDCH = null;
- this.oldFactory = null;
- this.shortType = null;
- this.dataSource = new URLDataSource(var1);
- this.oldFactory = factory;
- }
-
- private synchronized CommandMap getCommandMap() {
- return this.currentCommandMap != null ? this.currentCommandMap : CommandMap.getDefaultCommandMap();
- }
-
- public DataSource getDataSource() {
- if (this.dataSource == null) {
- if (this.objDataSource == null) {
- this.objDataSource = new DataHandlerDataSource(this);
- }
-
- return this.objDataSource;
- } else {
- return this.dataSource;
- }
- }
-
- public String getName() {
- return this.dataSource != null ? this.dataSource.getName() : null;
- }
-
- public String getContentType() {
- return this.dataSource != null ? this.dataSource.getContentType() : this.objectMimeType;
- }
-
- public InputStream getInputStream() throws IOException {
- Object var1 = null;
- if (this.dataSource != null) {
- var1 = this.dataSource.getInputStream();
- } else {
- DataContentHandler var2 = this.getDataContentHandler();
- if (var2 == null) {
- throw new UnsupportedDataTypeException("no DCH for MIME type " + this.getBaseType());
- }
-
- if (var2 instanceof ObjectDataContentHandler && ((ObjectDataContentHandler)var2).getDCH() == null) {
- throw new UnsupportedDataTypeException("no object DCH for MIME type " + this.getBaseType());
- }
-
- PipedOutputStream var4 = new PipedOutputStream();
- PipedInputStream var5 = new PipedInputStream(var4);
- (new Thread(new 1(this, var2, var4), "DataHandler.getInputStream")).start();
- var1 = var5;
- }
-
- return (InputStream)var1;
- }
-
- public void writeTo(OutputStream var1) throws IOException {
- if (this.dataSource != null) {
- Object var2 = null;
- byte[] var3 = new byte[8192];
- InputStream var8 = this.dataSource.getInputStream();
-
- int var4;
- try {
- while((var4 = var8.read(var3)) > 0) {
- var1.write(var3, 0, var4);
- }
- } finally {
- var8.close();
- Object var9 = null;
- }
- } else {
- DataContentHandler var10 = this.getDataContentHandler();
- var10.writeTo(this.object, this.objectMimeType, var1);
- }
-
- }
-
- public OutputStream getOutputStream() throws IOException {
- return this.dataSource != null ? this.dataSource.getOutputStream() : null;
- }
-
- public synchronized DataFlavor[] getTransferDataFlavors() {
- if (factory != this.oldFactory) {
- this.transferFlavors = emptyFlavors;
- }
-
- if (this.transferFlavors == emptyFlavors) {
- this.transferFlavors = this.getDataContentHandler().getTransferDataFlavors();
- }
-
- return this.transferFlavors;
- }
-
- public boolean isDataFlavorSupported(DataFlavor var1) {
- DataFlavor[] var2 = this.getTransferDataFlavors();
-
- for(int var3 = 0; var3 < var2.length; ++var3) {
- if (var2[var3].equals(var1)) {
- return true;
- }
- }
-
- return false;
- }
-
- public Object getTransferData(DataFlavor var1) throws UnsupportedFlavorException, IOException {
- return this.getDataContentHandler().getTransferData(var1, this.dataSource);
- }
-
- public synchronized void setCommandMap(CommandMap var1) {
- if (var1 != this.currentCommandMap || var1 == null) {
- this.transferFlavors = emptyFlavors;
- this.dataContentHandler = null;
- this.currentCommandMap = var1;
- }
-
- }
-
- public CommandInfo[] getPreferredCommands() {
- return this.dataSource != null ? this.getCommandMap().getPreferredCommands(this.getBaseType(), this.dataSource) : this.getCommandMap().getPreferredCommands(this.getBaseType());
- }
-
- public CommandInfo[] getAllCommands() {
- return this.dataSource != null ? this.getCommandMap().getAllCommands(this.getBaseType(), this.dataSource) : this.getCommandMap().getAllCommands(this.getBaseType());
- }
-
- public CommandInfo getCommand(String var1) {
- return this.dataSource != null ? this.getCommandMap().getCommand(this.getBaseType(), var1, this.dataSource) : this.getCommandMap().getCommand(this.getBaseType(), var1);
- }
-
- public Object getContent() throws IOException {
- return this.object != null ? this.object : this.getDataContentHandler().getContent(this.getDataSource());
- }
-
- public Object getBean(CommandInfo var1) {
- Object var2 = null;
-
- try {
- Object var3 = null;
- ClassLoader var6 = SecuritySupport.getContextClassLoader();
- if (var6 == null) {
- var6 = this.getClass().getClassLoader();
- }
-
- var2 = var1.getCommandObject(this, var6);
- } catch (IOException var4) {
- } catch (ClassNotFoundException var5) {
- }
-
- return var2;
- }
-
- private synchronized DataContentHandler getDataContentHandler() {
- if (factory != this.oldFactory) {
- this.oldFactory = factory;
- this.factoryDCH = null;
- this.dataContentHandler = null;
- this.transferFlavors = emptyFlavors;
- }
-
- if (this.dataContentHandler != null) {
- return this.dataContentHandler;
- } else {
- String var1 = this.getBaseType();
- if (this.factoryDCH == null && factory != null) {
- this.factoryDCH = factory.createDataContentHandler(var1);
- }
-
- if (this.factoryDCH != null) {
- this.dataContentHandler = this.factoryDCH;
- }
-
- if (this.dataContentHandler == null) {
- if (this.dataSource != null) {
- this.dataContentHandler = this.getCommandMap().createDataContentHandler(var1, this.dataSource);
- } else {
- this.dataContentHandler = this.getCommandMap().createDataContentHandler(var1);
- }
- }
-
- if (this.dataSource != null) {
- this.dataContentHandler = new DataSourceDataContentHandler(this.dataContentHandler, this.dataSource);
- } else {
- this.dataContentHandler = new ObjectDataContentHandler(this.dataContentHandler, this.object, this.objectMimeType);
- }
-
- return this.dataContentHandler;
- }
- }
-
- private synchronized String getBaseType() {
- if (this.shortType == null) {
- String var1 = this.getContentType();
-
- try {
- MimeType var2 = new MimeType(var1);
- this.shortType = var2.getBaseType();
- } catch (MimeTypeParseException var3) {
- this.shortType = var1;
- }
- }
-
- return this.shortType;
- }
-
- public static synchronized void setDataContentHandlerFactory(DataContentHandlerFactory var0) {
- if (factory != null) {
- throw new Error("DataContentHandlerFactory already defined");
- } else {
- SecurityManager var1 = System.getSecurityManager();
- if (var1 != null) {
- try {
- var1.checkSetFactory();
- } catch (SecurityException var3) {
- if (DataHandler.class.getClassLoader() != var0.getClass().getClassLoader()) {
- throw var3;
- }
- }
- }
-
- factory = var0;
- }
- }
-
- // $FF: synthetic method
- static Object access$000(DataHandler var0) {
- return var0.object;
- }
-
- // $FF: synthetic method
- static String access$100(DataHandler var0) {
- return var0.objectMimeType;
- }
- }
-